<?php

/**
 * Impress - Open source digital signage
 *
 * @link http://digitalsignage.tk
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 * @category Impress
 * @package Impress
 */

/**
 * This class provides access to output.
 *
 * @package Impress
 * @subpackage Core
 */

class ADS_Output{
    
    private static $regVars = array();
    private static $output = '';
    
    public static function register($name,$value){
        self::$regVars[$name] = $value;
    } 
    
    public static function renderOutput($template, $autoFlush = false){        
        $tEngine = new ADS_TemplateEngine();
        if(!is_file($tEngine->template_dir . $template)){
            throw new InvalidArgumentException(sprintf('Template %s does not exist.',$template));
        }
        //extract message stack
        $tEngine->assign('messages', ADS_MsgStack::getStack());
        //assign registered variables
        foreach (self::$regVars as $name => $value) {
            $tEngine->assign($name, $value);
        }
        //render output
        if($autoFlush){
            $tEngine->display($template);
        }else{
            self::$output = $tEngine->fetch($template);
        }
    }
    
    public static function flushOutput(){
        print self::$output;
        self::$output = '';
    }
    
    public static function appendToOutput($content){
        self::$output .= $content;
    } 
    
}
